package com.bt.springboot.common.util;

import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Component;

/**
 * @author zkx
 * @Date 2022/12/12 13:23
 */
@Component
public class CodeUtil {

	public String generate(String phoneNumber) {
		int hash = phoneNumber.hashCode();
		int encryption = 20221212;
		// 异或加密
		long result = hash ^ encryption;
		long nowTime = System.currentTimeMillis();
		result = result ^ nowTime;
		long code = result % 1000000;
		// 处理有负数的情况
		code = code < 0 ? -code : code;
		// 六位数：前面补0
		code = Long.parseLong(String.format("%06d",code));
		return code + "";
	}

	@Cacheable(key = "#phoneNumber",value = "cacheCode")
	public String getCacheCode(String phoneNumber){
		return null;
	}


}
